﻿using UnityEngine;

namespace BToolkit
{
    public class ARVideoPlayer : MonoBehaviour
    {
        public ARVideoPlayer_Unity unityPlayer;
        public ARVideoPlayer_EasyMT easyMoveTexture;
        ARVideoInfo info;

        public void Play(ARVideoInfo info)
        {
            if (this.info == null)
            {
                this.info = info;
                transform.localScale = Vector3.zero;
                if (info.isAVProMaskVideo)
                {
                    Destroy(unityPlayer.gameObject);
                    easyMoveTexture.gameObject.SetActive(true);
                    easyMoveTexture.Play(info.videoUrl);
                }
                else
                {
                    Destroy(easyMoveTexture.gameObject);
                    unityPlayer.gameObject.SetActive(true);
                    unityPlayer.Play(info.videoUrl);
                }
            }
        }

        public void OnGetedVideoSize(float videoW, float videoH)
        {
            transform.localPosition = new Vector3(0, 0, 0);
            transform.eulerAngles = Vector3.zero;
            Vector3 scale = Vector3.one;
            if (videoW / videoH >= 1 / info.aspectRatio)
            {
                scale.y = videoH / videoW;
            }
            else
            {
                scale.y = 1 / info.aspectRatio;
                scale.x = scale.y * videoW / videoH;
            }
            transform.localScale = scale;
        }

    }
}